<!--设置签名弹窗-->
<script setup>

import GlobalDialog from "@/components/common/dialog/GlobalDialog.vue";
import PostTextArea from "@/components/post/PostTextArea.vue";
import {useStore} from "vuex";
import {ref} from "vue";

const store = useStore();

// 弹窗名称
const name = 'signature_set'

const signatureSet = () => {
  loading.value = true
  return store.dispatch("User/signatureSet", {userId: userId.value, sign: content.value}).then(res => {
    if (res) {
      closeDialog()
    }
  }).finally(() => {
    loading.value = false;
  })
}
const closeDialog = () => store.commit("Dialog/closeDialog", name)

const loading = ref(false);
const userId = ref();
const content = ref();
const editor = ref();
const onOpen = (e) => {
  userId.value = e.userId
  editor.value.init(e.signature.replace(/<br\/*>/g, "\n"))
}

</script>

<template>
  <global-dialog :name="name" destroy-on-close @open="onOpen">
    <template #default="{data}">
      <!--正文文本框-->
      <div style="text-align: left">
        <post-text-area ref="editor" v-model="content"/>
      </div>
      <el-button :loading="loading" size="small" type="success" @click="signatureSet">提交</el-button>
    </template>
    <template #header="{data}">
      设置签名
    </template>
  </global-dialog>
</template>

<style scoped>

</style>